<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;

use App\Logic\LiveLogic;
use App\Model\Live;
use Hyperf\HttpServer\Annotation\AutoController;
use Psr\Http\Message\ResponseInterface;

#[AutoController]
class TcloudController extends AbstractController
{
    /**
     * 推流回调.
     */
    public function pushStream(): ResponseInterface
    {
        $input = $this->request->all();
        $this->logger->warning('pushStream', $input);
        LiveLogic::startLive($input);
        return $this->apiReturn();
    }

    /**
     * 断流回调.
     */
    public function cutoffStream(): ResponseInterface
    {
        $input = $this->request->all();
        $this->logger->warning('cutoffStream', $input);
        Live::query()->where('room_id', $input['stream_id'])->update(['cute_stream_time' => time()]);
        return $this->apiReturn();
    }

    /**
     * 截图回调.
     */
    public function screenshot(): ResponseInterface
    {
        $input = $this->request->all();
        $this->logger->warning('screenshot', $input);
        return $this->apiReturn();
    }

    /**
     * 异常回调.
     */
    public function error(): ResponseInterface
    {
        $input = $this->request->all();
        $this->logger->warning('screenshot', $input);
        return $this->apiReturn();
    }
}
